package com.elcl.util;

import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.util.Log;

/**
 * Created by lichunlin on 16/4/5.
 */
public class SpannableStringUtils {

    //设置字体大小
    public static SpannableString setSize(String content, int stringSize) {
        SpannableString spanText = new SpannableString(content);
        //第二个参数boolean dip，如果为true，表示前面的字体大小单位为dip，否则为像素，同上
        AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(stringSize, true);
        spanText.setSpan(absoluteSizeSpan, 0, spanText.length(),
                Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        return spanText;
    }

    //设置字体颜色
    public static SpannableString setColor(String content, int color) {
        SpannableString spanText = new SpannableString(content);
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(color);
        spanText.setSpan(foregroundColorSpan, 0, spanText.length(),
                Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        return spanText;
    }

    //同时设置字体大小和颜色
    public static SpannableString setColorAndSize(String content, int color, int stringSize) {
        SpannableString spanText = new SpannableString(content);
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(color);
        spanText.setSpan(foregroundColorSpan, 0, spanText.length(),
                Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(stringSize, true);
        spanText.setSpan(absoluteSizeSpan, 0, spanText.length(),
                Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        return spanText;
    }


}
